<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('权重设置')" />
	<th:block th:include="include :: bootstrap-editable-css" />
	<th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
<div class="container-div">
	<div class="row">
		<div class="col-sm-12 search-collapse">
			<form id="role-form">
				<input type="hidden" id="channel" name="channel" th:value="${tPayChannel.channel}">
				<div class="select-list">
					<ul>
						<li>
							<label>用户类型：</label>
							<select name="merchantType" class="form-control m-b" th:with="type=${@dict.getType('sys_merchant_type')}">
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
							</select>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>


		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table"></table>
		</div>
	</div>
</div>

	<th:block th:include="include :: footer" />
	<th:block th:include="include :: bootstrap-table-editable-js" />
	<th:block th:include="include :: select2-js" />

	<script th:inline="javascript">
		var prefix = ctx + "business/channel"
		var sysMerchantTypeData = [[${@dict.getType('sys_merchant_type')}]];

		$(function() {
			var options = {
				url: prefix + "/ratioCfglist",
				showSearch: false,
				showRefresh: true,
				showToggle: false,
				showColumns: false,
				showPageGo: true,
				onEditableSave: onEditableSave,
				columns: [
					{
						field : 'userId',
						title : '商户编码'
					},
					{
						field : 'userName',
						title : '商户名称'
					},
					{
						field : 'merchantType',
						title : '商户类型',
						formatter: function(value, item, index) {
							return $.table.selectDictLabel(sysMerchantTypeData, item.merchantType);
						}
					},
					{
						field : 'type',
						title : '通道类型'
					},
					{
						field : 'channel',
						title : '通道编码'
					},
					{
						field : 'ratio',
						title : '权重值',
						editable : {
							type : 'text',
							title : '权重值',
							emptytext : "【权重值】为空",
							validate : function(value) {
								var reg = /^(1|([1-9]\d{0,1})|100)$/;
								if (!reg.test(value)) {
									return '权重只能是数字,且只能是1-100之间的数字';
								}

							}
						}
					}]
			};
			$.table.init(options);
		});

		function queryParams(params) {
			var search = $.table.queryParams(params);
			return search;
		}
		function onEditableSave (field, row, rowIndex, oldValue, $el) {
			// alert("字段名：" + field + "，当前值：" + row[field]  + "，旧值：" + oldValue);
			var data = {"id": row["id"], ratio:  row[field], merchantType: row["merchantType"]};
			var config = {
				url: prefix + "/ratioCfg",
				type: "post",
				dataType: "json",
				data: data,
				beforeSend: function () {
					$.modal.loading("正在处理中，请稍后...");
					// $.modal.disable();
				},
				success: function (result) {
					if (result.code == web_status.SUCCESS) {
						$.modal.msgSuccess(result.msg);
					} else {
						$.modal.msgError(result.msg);
					}
					$.modal.closeLoading();
				}
			};
			$.ajax(config)
		}


	</script>
</body>

</html>
